﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;

namespace Survey.Entity.Services
{
    [Serializable]
    public class User : Persistent<int>
    {
        #region members
        string _currentRole;
        IList<string> _roles = new List<string>();
        #endregion members

        public virtual string Login { get; set; }

        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }

        //public virtual Member Member { get; set; }

        #region Role
        public virtual string CurrentRole
        {
            get
            {
                if (Roles.Count() > 0)
                {
                    if (_currentRole.IsNull()
                        || !Roles.Contains(_currentRole))
                    {
                        return Roles[0];
                    }
                    return _currentRole;
                }
                return null;
            }
            set { _currentRole = value; }
        }

        public virtual IList<string> Roles
        {
            get { return _roles; }
            set
            {
                Contract.Requires(value.Is(), "Cannot set User Roles to null, provide collection");
                _roles = value;
            }
        }
        #endregion Role

        public override string ToDisplay()
        {
            if (LastName.IsNotEmpty())
            {
                return LastName + " " + FirstName;
            }
            return Login;
        }

        protected override string GetDomainObjectSignature()
        {
            return Login;
        }

        public override object Clone()
        {
            var entity = base.Clone() as User;

            entity.Roles = new List<string>(Roles);

            return entity;
        }
    }
}